package com.example.demo.web;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
public class FoodController {
    // http://127.0.0.1:8080/hello?name=food
    @RequestMapping("/hello")
    @ResponseBody
    public String hello(@RequestParam(name="name",defaultValue =  "  我的菜单") String name){
       return "hello"+name;
    }


    @RequestMapping("/dish")
    @ResponseBody
    public Food dish() {
        Food dish = new Food();
        dish.setName("宫保鸡丁");
        dish.setPrice(102.5);
        return dish;
    }

    @RequestMapping("/save_food")
    @ResponseBody
    public String saveUser(Food f) {
        return "user will save: name=" + f.getName() + ", 价格=" + f.getPrice();
    }

    @ModelAttribute
    public void parseFood(@RequestParam(name = "name", defaultValue = "unknown food") String name
            , @RequestParam(name = "price", defaultValue = "123.5") Double price, Food food) {
        food.setName("柳职杀猪菜");
        food.setPrice(price);
    }



    @RequestMapping("/html")
    public String html(){
        return "index1.html";
    }
}
